Micron Document
<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Conditional (computer programming)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Conditional_(computer_programming)"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Conditional_computer_programming rootpage-Conditional_computer_programming skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Conditional (computer programming)</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">


<p>In <a href="Computer_science" title="Computer science">computer science</a>, <b>conditionals</b> (that is, <b>conditional statements</b>, <b>conditional expressions</b> and <b>conditional constructs</b>) are <a href="Programming_language" title="Programming language">programming language</a> constructs that perform different computations or actions or return different values depending on the value of a <a href="Boolean_data_type" title="Boolean data type">Boolean</a> expression, called a <i>condition</i>.
</p><p>Conditionals are typically implemented by selectively executing instructions. Although <a href="Dynamic_dispatch" title="Dynamic dispatch">dynamic dispatch</a> is not usually classified as a conditional construct, it is another way to select between alternatives at <a href="Run_time_(program_lifecycle_phase)" class="mw-redirect" title="Run time (program lifecycle phase)">runtime</a>.
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="Terminology">Terminology</h2></div>
<p>Conditional <a href="Statement_(computer_science)" title="Statement (computer science)">statements</a> are imperative constructs executed for side-effect, while conditional <a href="Expression_(computer_science)" title="Expression (computer science)">expressions</a> return values. Many programming languages (such as C) have distinct conditional statements and conditional expressions. Although in pure <a href="Functional_programming" title="Functional programming">functional programming</a>, conditional expressions do not have <a href="Side_effect_(computer_science)" title="Side effect (computer science)">side-effects</a>, many languages with conditional expressions (such as Lisp) support conditional side-effects.
</p>
<div class="mw-heading mw-heading2"><h2 id="If–then(–else)">If–then(–else)</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1236090951">
/* start https://en.wikipedia.org/ */


.mw-parser-output .hatnote{font-style:italic}.mw-parser-output div.hatnote{padding-left:1.6em;margin-bottom:0.5em}.mw-parser-output .hatnote i{font-style:normal}.mw-parser-output .hatnote+link+.hatnote{margin-top:-0.5em}@media print{body.ns-0 .mw-parser-output .hatnote{display:none!important}}


/* end https://en.wikipedia.org/ */
</style><div role="note" class="hatnote navigation-not-searchable">"if-then-else" redirects here. For the album, see <a href="If_Then_Else" title="If Then Else">If Then Else</a>. For the TV episode, see <a href="If-Then-Else" title="If-Then-Else">If-Then-Else</a>.</div>
<p>The <code>if–then</code> or <code>if–then–else</code> construction is used in many programming languages. Although the syntax varies from language to language, the basic structure (in <a href="Pseudocode" title="Pseudocode">pseudocode</a> form) looks like this:
</p>
<pre><b>If</b> (Boolean condition) <b>Then</b>
(consequent)
<b>Else</b>
(alternative)
<b>End If</b>
</pre>
<p>For example:
</p>
<pre><b>If</b> stock = 0 <b>Then</b>
message = order new stock
<b>Else</b>
message = there is stock
<b>End If</b>
</pre>
<p>In the example code above, the part represented by <i>(Boolean condition)</i> constitutes a conditional <i>expression</i>, having intrinsic value (e.g., it may be substituted by either of the values <code>True</code> or <code>False</code>) but having no intrinsic meaning. In contrast, the combination of this expression, the <code>If</code> and <code>Then</code> surrounding it, and the consequent that follows afterward constitute a conditional <i>statement</i>, having intrinsic meaning (e.g., expressing a coherent logical rule) but no intrinsic value.
</p><p>When an <a href="Interpreter_(computing)" title="Interpreter (computing)">interpreter</a> finds an <code>If</code>, it expects a <a href="Boolean_data_type" title="Boolean data type">Boolean</a> condition – for example, <code>x &gt; 0</code>, which means "the variable x contains a number that is greater than zero" – and evaluates that condition. If the condition is <code>true</code>, the statements following the <code>then</code> are executed. Otherwise, the execution continues in the following branch – either in the <code>else</code> <a href="Block_(programming)" title="Block (programming)">block</a> (which is usually optional), or if there is no <code>else</code> branch, then after the <code>end If</code>.
</p><p>After either branch has been executed, <a href="Control_flow" title="Control flow">control</a> returns to the point after the <code>end If</code>.
</p>
<div class="mw-heading mw-heading3"><h3 id="History_and_development">History and development</h3></div>
<p>In early programming languages, especially some dialects of <a href="BASIC" title="BASIC">BASIC</a> in the 1980s <a href="Home_computer" title="Home computer">home computers</a>, an <code>if–then</code> statement could only contain <code><a href="GOTO" class="mw-redirect" title="GOTO">GOTO</a></code> statements (equivalent to a <a href="Branch_(computer_science)" title="Branch (computer science)">branch</a> instruction). This led to a hard-to-read style of programming known as <a href="Spaghetti_programming" class="mw-redirect" title="Spaghetti programming">spaghetti programming</a>, with programs in this style called <i>spaghetti code</i>. As a result, <a href="Structured_programming" title="Structured programming">structured programming</a>, which allows (virtually) arbitrary statements to be put in statement blocks inside an <code>if</code> statement, gained in popularity, until it became the norm even in most BASIC programming circles. Such mechanisms and principles were based on the older but more advanced <a href="ALGOL" title="ALGOL">ALGOL</a> family of languages, and ALGOL-like languages such as <a href="Pascal_(programming_language)" title="Pascal (programming language)">Pascal</a> and <a href="Modula-2" title="Modula-2">Modula-2</a> influenced modern BASIC variants for many years. While it is possible while using only <code>GOTO</code> statements in <code>if–then</code> statements to write programs that are not spaghetti code and are just as well structured and readable as programs written in a structured programming language, structured programming makes this easier and enforces it. Structured <code>if–then–else</code> statements like the example above are one of the key elements of structured programming, and they are present in most popular high-level programming languages such as <a href="C_(programming_language)" title="C (programming language)">C</a>, <a href="Java_(programming_language)" title="Java (programming language)">Java</a>, <a href="JavaScript" title="JavaScript">JavaScript</a> and <a href="Visual_Basic" title="Visual Basic">Visual Basic</a> .
</p>
<div class="mw-heading mw-heading4"><h4 id="The_&quot;dangling_else&quot;_problem">The "dangling else" problem</h4></div>
<div role="note" class="hatnote navigation-not-searchable">Main article: <a href="Dangling_else" title="Dangling else">Dangling else</a></div>
<p>The <code>else</code> keyword is made to target a specific <code>if–then</code> statement preceding it, but for <a href="Nesting_(computing)" title="Nesting (computing)">nested</a> <code>if–then</code> statements, classic programming languages such as <a href="ALGOL_60" title="ALGOL 60">ALGOL 60</a> struggled to define which specific statement to target. Without clear boundaries for which statement is which, an <code>else</code> keyword could target any preceding <code>if–then</code> statement in the nest, as parsed.
</p>
<pre><b>if</b> a <b>then</b> <b>if</b> b <b>then</b> s <b>else</b> s2
</pre>
<p>can be parsed as
</p>
<pre><b>if</b> a <b>then</b> (<b>if</b> b <b>then</b> s) <b>else</b> s2
</pre>
<p>or
</p>
<pre><b>if</b> a <b>then</b> (<b>if</b> b <b>then</b> s <b>else</b> s2)
</pre>
<p>depending on whether the <code>else</code> is associated with the first <code>if</code> or second <code>if</code>. This is known as the <a href="Dangling_else" title="Dangling else">dangling else</a> problem, and is resolved in various ways, depending on the language (commonly via the <code>end if</code> statement or <code>{...}</code> brackets).
</p>
<div class="mw-heading mw-heading3"><h3 id="Else_if">Else if</h3></div>
<p>By using <code>else if</code>, it is possible to combine several conditions. Only the statements following the first condition that is found to be true will be executed. All other statements will be skipped.
</p>
<pre><b>if</b> condition <b>then</b>
<i>-- statements</i>
<b>elseif</b> condition <b>then</b>
<i>-- more statements</i>
<b>elseif</b> condition <b>then</b>
<i>-- more statements;</i>
...
<b>else</b>
<i>-- other statements;</i>
<b>end if</b>;
</pre>
<p>For example, for a shop offering as much as a 30% discount for an item:
</p>
<pre><b>if</b> discount &lt; 11% <b>then</b>
print (you have to pay $30)
<b>elseif</b> discount &lt; 21% <b>then</b>
print (you have to pay $20)
<b>elseif</b> discount &lt; 31% <b>then</b>
print (you have to pay $10)
<b>end if</b>;
</pre>
<p>In the example above, if the discount is 10%, then the first if statement will be evaluated as true and "you have to pay $30" will be printed out. All other statements below that first if statement will be skipped.
</p><p>The <code>elseif</code> statement, in the <a href="Ada_(programming_language)" title="Ada (programming language)">Ada</a> language for example, is simply <a href="Syntactic_sugar" title="Syntactic sugar">syntactic sugar</a> for <code>else</code> followed by <code>if</code>. In Ada, the difference is that only one <code>end if</code> is needed, if one uses <code>elseif</code> instead of <code>else</code> followed by <code>if</code>. <a href="PHP" title="PHP">PHP</a> uses the <code>elseif</code> keyword<sup id="cite_ref-php_elseif_1-0" class="reference"><a href="#cite_note-php_elseif-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> both for its curly brackets or colon syntaxes. <a href="Perl" title="Perl">Perl</a> and <a href="Ruby_(programming_language)" title="Ruby (programming language)">Ruby</a> provide the keyword <code>elsif</code> to avoid the large number of braces that would be required by multiple <code>if</code> and <code>else</code> statements. <a href="Python_(programming_language)" title="Python (programming language)">Python</a> uses the special keyword <code>elif</code> because structure is denoted by indentation rather than braces, so a repeated use of <code>else</code> and <code>if</code> would require increased indentation after every condition. Some implementations of <a href="BASIC" title="BASIC">BASIC</a>, such as <a href="Visual_Basic" title="Visual Basic">Visual Basic</a>,<sup id="cite_ref-vb_elseif_2-0" class="reference"><a href="#cite_note-vb_elseif-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup> use <code>ElseIf</code> too. Similarly, the earlier UNIX shells (later gathered up to the POSIX shell syntax<sup id="cite_ref-posixshell_3-0" class="reference"><a href="#cite_note-posixshell-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup>) use elif too, but giving the choice of delimiting with spaces, line breaks, or both.
</p><p>However, in many languages more directly descended from Algol, such as <a href="Simula_(programming_language)" class="mw-redirect" title="Simula (programming language)">Simula</a>, <a href="Pascal_(programming_language)" title="Pascal (programming language)">Pascal</a>, BCPL and <a href="C_(programming_language)" title="C (programming language)">C</a>, this special syntax for the <code>else if</code> construct is not present, nor is it present in the many syntactical derivatives of C, such as <a href="Java_(programming_language)" title="Java (programming language)">Java</a>, <a href="ECMAScript" title="ECMAScript">ECMAScript</a>, and so on. This works because in these languages, any <i>single</i> statement (in this case <code>if <i>cond</i></code>...) can follow a conditional without being enclosed in a block.
</p><p>This design choice has a slight "cost". Each <code>else if</code> branch effectively adds an extra nesting level. This complicates the job for the compiler (or the people who write the compiler), because the compiler must analyse and implement arbitrarily long <code>else if</code> chains recursively.
</p><p>If all terms in the sequence of conditionals are testing the value of a single expression (e.g., <code>if x=0</code> ... <code>else if x=1</code> ... <code>else if x=2</code>...), an alternative is the <a href="Switch_statement" title="Switch statement">switch statement</a>, also called case-statement or select-statement. Conversely, in languages that do not have a switch statement, these can be produced by a sequence of <code>else if</code> statements.
</p>
<div class="mw-heading mw-heading3"><h3 id="If–then–else_expressions">If–then–else expressions</h3></div>
<div role="note" class="hatnote navigation-not-searchable">See also: <a href="Ternary_conditional_operator" title="Ternary conditional operator">Ternary conditional operator</a></div>
<p>Many languages support <i>conditional expressions</i>, which are similar to if statements, but return a value as a result. Thus, they are true expressions (which evaluate to a value), not statements (which may not be permitted in the context of a value). The concept of conditional expressions was first developed by <a href="John_McCarthy_(computer_scientist)" title="John McCarthy (computer scientist)">John McCarthy</a> during his research into symbolic processing and LISP in the late 1950s.
</p>
<div class="mw-heading mw-heading4"><h4 id="Algol_family">Algol family</h4></div>
<p><a href="ALGOL_60" title="ALGOL 60">ALGOL 60</a> and some other members of the <a href="ALGOL" title="ALGOL">ALGOL</a> family allow <code>if–then–else</code> as an expression. The idea of including conditional expressions was suggested by John McCarthy, though the ALGOL committee decided to use English words rather than McCarthy's mathematical syntax:
</p>
<pre>myvariable&nbsp;:= if x &gt; 20 then 1 else 2
</pre>
<div class="mw-heading mw-heading4"><h4 id="Lisp_dialects">Lisp dialects</h4></div>
<p>Conditional expressions have always been a fundamental part of <a href="Lisp_(programming_language)" title="Lisp (programming language)">Lisp</a><span class="nowrap">&nbsp;</span>. In pure LISP, the <code>COND</code> function is used. In dialects such as <a href="Scheme_(programming_language)" title="Scheme (programming language)">Scheme</a>, <a href="Racket_(programming_language)" title="Racket (programming language)">Racket</a> and <a href="Common_Lisp" title="Common Lisp">Common Lisp</a><span class="nowrap">&nbsp;</span>:
</p>
<div class="mw-highlight mw-highlight-lang-scheme mw-content-ltr" dir="ltr"><pre><span class="c1">;; Scheme</span>
<span class="p">(</span><span class="k">define</span><span class="w"> </span><span class="p">(</span><span class="nf">myvariable</span><span class="w"> </span><span class="nv">x</span><span class="p">)</span><span class="w"> </span><span class="p">(</span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="nb">&gt;</span><span class="w"> </span><span class="nv">x</span><span class="w"> </span><span class="mi">12</span><span class="p">)</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="mi">2</span><span class="p">))</span><span class="w"> </span><span class="c1">; Assigns 'myvariable' to 1 or 2, depending on the value of 'x'</span>
</pre></div>
<div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span class="c1">;; Common Lisp</span>
<span class="p">(</span><span class="k">let</span><span class="w"> </span><span class="p">((</span><span class="nv">x</span><span class="w"> </span><span class="mi">10</span><span class="p">))</span>
<span class="w"> </span><span class="p">(</span><span class="k">setq</span><span class="w"> </span><span class="nv">myvariable</span><span class="w"> </span><span class="p">(</span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="nb">&gt;</span><span class="w"> </span><span class="nv">x</span><span class="w"> </span><span class="mi">12</span><span class="p">)</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="mi">4</span><span class="p">)))</span><span class="w"> </span><span class="c1">; Assigns 'myvariable' to 2</span>
</pre></div>
<div role="note" class="hatnote navigation-not-searchable">See also: <a href="McCarthy_Formalism" title="McCarthy Formalism">McCarthy Formalism</a></div>
<div class="mw-heading mw-heading4"><h4 id="Haskell">Haskell</h4></div>
<div role="note" class="hatnote navigation-not-searchable">Main article: <a href="Haskell_(programming_language)" class="mw-redirect" title="Haskell (programming language)">Haskell (programming language)</a></div>
<p>In <a href="Haskell_(programming_language)" class="mw-redirect" title="Haskell (programming language)">Haskell</a> 98, there is only an <i>if expression</i>, no <i>if statement</i>, and the <code>else</code> part is compulsory, as every expression must have some value.<sup id="cite_ref-haskell98report_4-0" class="reference"><a href="#cite_note-haskell98report-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup> Logic that would be expressed with conditionals in other languages is usually expressed with <a href="Pattern_matching" title="Pattern matching">pattern matching</a> in recursive functions.
</p><p>Because Haskell is <a href="Lazy_evaluation" title="Lazy evaluation">lazy</a>, it is possible to write control structures, such as <i>if</i>, as ordinary expressions; the lazy evaluation means that an <i>if function</i> can evaluate only the condition and proper branch (where a strict language would evaluate all three). It can be written like this:<sup id="cite_ref-haskell-ifthenelse-proposal_5-0" class="reference"><a href="#cite_note-haskell-ifthenelse-proposal-5"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><pre><span class="nf">if'</span><span class="w"> </span><span class="ow">::</span><span class="w"> </span><span class="kt">Bool</span><span class="w"> </span><span class="ow">-&gt;</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="ow">-&gt;</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="ow">-&gt;</span><span class="w"> </span><span class="n">a</span>
<span class="nf">if'</span><span class="w"> </span><span class="kt">True</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="kr">_</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">x</span>
<span class="nf">if'</span><span class="w"> </span><span class="kt">False</span><span class="w"> </span><span class="kr">_</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">y</span>
</pre></div>
<div class="mw-heading mw-heading4"><h4 id="C-like_languages">C-like languages</h4></div>
<p><a href="C_(programming_language)" title="C (programming language)">C</a> and C-like languages have a special <a href="Ternary_operator" class="mw-redirect" title="Ternary operator">ternary operator</a> (<a href="%3F%3A" class="mw-redirect" title="?:">?:</a>) for conditional expressions with a function that may be described by a template like this:
</p>
<pre><code>condition&nbsp;? evaluated-when-true&nbsp;: evaluated-when-false</code>
</pre>
<p>This means that it can be inlined into expressions, unlike if-statements, in C-like languages:
</p>
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span class="n">my_variable</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">10</span><span class="w"> </span><span class="o">?</span><span class="w"> </span><span class="s">"foo"</span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="s">"bar"</span><span class="p">;</span><span class="w"> </span><span class="c1">// In C-like languages</span>
</pre></div>
<p>which can be compared to the Algol-family if–then–else <i>expressions</i> (in contrast to a <i>statement</i>) (and similar in Ruby and Scala, among others).
</p><p>To accomplish the same using an if-statement, this would take more than one line of code (under typical layout conventions), and require mentioning "my_variable" twice:
</p>
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">10</span><span class="p">)</span>
<span class="w"> </span><span class="n">my_variable</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"foo"</span><span class="p">;</span>
<span class="k">else</span>
<span class="w"> </span><span class="n">my_variable</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"bar"</span><span class="p">;</span>
</pre></div>
<p>Some argue that the explicit if/then statement is easier to read and that it may compile to more efficient code than the ternary operator,<sup id="cite_ref-6" class="reference"><a href="#cite_note-6"><span class="cite-bracket">[</span>6<span class="cite-bracket">]</span></a></sup> while others argue that concise expressions are easier to read than statements spread over several lines containing repetition.
</p>
<div class="mw-heading mw-heading4"><h4 id="Visual_Basic">Visual Basic</h4></div>
<div role="note" class="hatnote navigation-not-searchable">Main article: <a href="Visual_Basic" title="Visual Basic">Visual Basic</a></div>
<p>In <a href="Visual_Basic" title="Visual Basic">Visual Basic</a> and some other languages, a function called <code><a href="IIf" title="IIf">IIf</a></code> is provided, which can be used as a conditional expression. However, it does not behave like a true conditional expression, because both the true and false branches are always evaluated; it is just that the result of one of them is thrown away, while the result of the other is returned by the IIf function.
</p>
<div class="mw-heading mw-heading4"><h4 id="Tcl">Tcl</h4></div>
<div role="note" class="hatnote navigation-not-searchable">Main article: <a href="Tcl" title="Tcl">Tcl</a></div>
<p>In <a href="Tcl" title="Tcl">Tcl</a> <code>if</code> is not a keyword but a function (in Tcl known as command or <code>proc</code>). For example
</p>
<div class="mw-highlight mw-highlight-lang-tcl mw-content-ltr" dir="ltr"><pre><span class="k">if</span><span class="w"> </span><span class="k">{</span><span class="nv">$x</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="nv">10</span><span class="k">}</span><span class="w"> </span><span class="k">{</span>
<span class="w"> </span><span class="nb">puts</span><span class="w"> </span><span class="s2">"Foo!"</span>
<span class="k">}</span>
</pre></div>
<p>invokes a function named <code>if</code> passing 2 arguments: The first one being the condition and the second one being the true branch. Both arguments are passed as strings (in Tcl everything within curly brackets is a string).
</p><p>In the above example the condition is not evaluated before calling the function. Instead, the implementation of the <code>if</code> function receives the condition as a string value and is responsible to evaluate this string as an expression in the callers scope.<sup id="cite_ref-7" class="reference"><a href="#cite_note-7"><span class="cite-bracket">[</span>7<span class="cite-bracket">]</span></a></sup>
</p><p>Such a behavior is possible by using <code>uplevel</code> and <code>expr</code> commands:
</p>
<dl><dd>Uplevel makes it possible to implement new control constructs as Tcl procedures (for example, uplevel could be used to implement the while construct as a Tcl procedure).<sup id="cite_ref-8" class="reference"><a href="#cite_note-8"><span class="cite-bracket">[</span>8<span class="cite-bracket">]</span></a></sup></dd></dl>
<p>Because <code>if</code> is actually a function it also returns a value:
</p>
<dl><dd>The return value from the command is the result of the body script that was executed, or an <a href="Empty_string" title="Empty string">empty string</a> if none of the expressions was non-zero and there was no bodyN.<sup id="cite_ref-9" class="reference"><a href="#cite_note-9"><span class="cite-bracket">[</span>9<span class="cite-bracket">]</span></a></sup></dd></dl>
<div class="mw-heading mw-heading4"><h4 id="Rust">Rust</h4></div>
<div role="note" class="hatnote navigation-not-searchable">Main article: <a href="Rust_(programming_language)" title="Rust (programming language)">Rust (programming language)</a></div>
<p>In <a href="Rust_(programming_language)" title="Rust (programming language)">Rust</a>, <code>if</code> is always an expression. It evaluates to the value of whichever branch is executed, or to the unit type <code>()</code> if no branch is executed. If a branch does not provide a return value, it evaluates to <code>()</code> by default. To ensure the <code>if</code> expression's type is known at <a href="Compile_time" title="Compile time">compile time</a>, each branch must evaluate to a value of the same type. For this reason, an <code>else</code> branch is effectively compulsory unless the other branches evaluate to <code>()</code>, because an <code>if</code> without an <code>else</code> can always evaluate to <code>()</code> by default.<sup id="cite_ref-10" class="reference"><a href="#cite_note-10"><span class="cite-bracket">[</span>10<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-highlight mw-highlight-lang-rust mw-content-ltr" dir="ltr"><pre><span class="c1">// Assign my_variable some value, depending on the value of x</span>
<span class="kd">let</span><span class="w"> </span><span class="n">my_variable</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">20</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="mi">1</span>
<span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="mi">2</span>
<span class="p">};</span>

<span class="c1">// This variant will not compile because 1 and () have different types</span>
<span class="kd">let</span><span class="w"> </span><span class="n">my_variable</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">20</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="mi">1</span>
<span class="p">};</span>

<span class="c1">// Values can be omitted when not needed</span>
<span class="k">if</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">20</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">"x is greater than 20"</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="Guarded_conditionals">Guarded conditionals</h3></div>
<p>The <a href="Guarded_Command_Language" title="Guarded Command Language">Guarded Command Language</a> (GCL) of <a href="Edsger_W._Dijkstra" title="Edsger W. Dijkstra">Edsger Dijkstra</a> supports conditional execution as a list of commands consisting of a Boolean-valued <a href="Guard_(computer_science)" title="Guard (computer science)">guard</a> (corresponding to a <i>condition</i>) and its corresponding statement. In GCL, exactly one of the statements whose guards is true is evaluated, but which one is arbitrary. In this code
</p>
<pre><b>if</b> G0 → S0
□ G1 → S1
...
□ Gn → Sn
<b>fi</b>
</pre>
<p>the G<sub><i>i</i></sub>'s are the guards and the S<sub><i>i</i></sub>'s are the statements. If none of the guards is true, the program's behavior is undefined.
</p><p>GCL is intended primarily for reasoning about programs, but similar notations have been implemented in <a href="Concurrent_Pascal" title="Concurrent Pascal">Concurrent Pascal</a> and <a href="Occam_(programming_language)" title="Occam (programming language)">occam</a>.
</p>
<div class="mw-heading mw-heading3"><h3 id="Arithmetic_if">Arithmetic if</h3></div>
<p>Up to <a href="Fortran_77" class="mw-redirect" title="Fortran 77">Fortran 77</a>, the language Fortran has had an arithmetic <i>if</i> statement which jumps to one of three labels depending on whether its argument <i>e</i> is <span class="nowrap"><i>e</i> &lt; 0,</span> <span class="nowrap"><i>e</i> = 0,</span> <span class="nowrap"><i>e</i> &gt; 0.</span> This was the earliest conditional statement in Fortran.<sup id="cite_ref-fortran77_11-0" class="reference"><a href="#cite_note-fortran77-11"><span class="cite-bracket">[</span>11<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading4"><h4 id="Syntax">Syntax</h4></div>
<div class="mw-highlight mw-highlight-lang-fortran mw-content-ltr" dir="ltr"><pre><span class="k">IF</span><span class="w"> </span><span class="p">(</span><span class="n">e</span><span class="p">)</span><span class="w"> </span><span class="n">label1</span><span class="p">,</span><span class="w"> </span><span class="n">label2</span><span class="p">,</span><span class="w"> </span><span class="n">label3</span>
</pre></div>
<p>Where e is a numeric expression of type <code>integer</code>, <code>real</code>, or <code>double precision</code>.
</p>
<div class="mw-heading mw-heading4"><h4 id="Semantics">Semantics</h4></div>
<p>This is equivalent to this sequence, where <i>e</i> is evaluated only once.
</p>
<div class="mw-highlight mw-highlight-lang-fortran mw-content-ltr" dir="ltr"><pre><span class="k">IF</span><span class="w"> </span><span class="p">(</span><span class="n">e</span><span class="w"> </span><span class="p">.</span><span class="n">LT</span><span class="p">.</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span><span class="w"> </span><span class="k">GOTO</span><span class="w"> </span><span class="n">label1</span>
<span class="k">IF</span><span class="w"> </span><span class="p">(</span><span class="n">e</span><span class="w"> </span><span class="p">.</span><span class="n">EQ</span><span class="p">.</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span><span class="w"> </span><span class="k">GOTO</span><span class="w"> </span><span class="n">label2</span>
<span class="k">IF</span><span class="w"> </span><span class="p">(</span><span class="n">e</span><span class="w"> </span><span class="p">.</span><span class="n">GT</span><span class="p">.</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span><span class="w"> </span><span class="k">GOTO</span><span class="w"> </span><span class="n">label3</span>
</pre></div>
<div class="mw-heading mw-heading4"><h4 id="Stylistics">Stylistics</h4></div>
<p>Arithmetic <i>if</i> is an unstructured control statement, and is not used in <a href="Structured_programming" title="Structured programming">structured programming</a>.
</p><p>In practice it has been observed that most arithmetic <code>IF</code> statements reference the following statement with one or two of the labels.
</p><p>This was the only conditional control statement in the original implementation of Fortran on the <a href="IBM_704" title="IBM 704">IBM 704</a> computer. On that computer the test-and-branch op-code had three addresses for those three states. Other computers would have "flag" registers such as positive, zero, negative, even, overflow, carry, associated with the last arithmetic operations and would use instructions such as 'Branch if accumulator negative' then 'Branch if accumulator zero' or similar. Note that the expression is evaluated <i>once only</i>, and in cases such as integer arithmetic where overflow may occur, the overflow or carry flags would be considered also.
</p>
<div class="mw-heading mw-heading3"><h3 id="Object-oriented_implementation_in_Smalltalk">Object-oriented implementation in Smalltalk</h3></div>
<p>In contrast to other languages, in <a href="Smalltalk" title="Smalltalk">Smalltalk</a> the conditional statement is not a <a href="Language_construct" title="Language construct">language construct</a> but defined in the class <code>Boolean</code> as an abstract method that takes two parameters, both <a href="Closure_(computer_science)" class="mw-redirect" title="Closure (computer science)">closures</a>. <code>Boolean</code> has two subclasses, <code>True</code> and <code>False</code>, which both define the method, <code>True</code> executing the first closure only, <code>False</code> executing the second closure only.<sup id="cite_ref-Smalltalk_conditionals_12-0" class="reference"><a href="#cite_note-Smalltalk_conditionals-12"><span class="cite-bracket">[</span>12<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-highlight mw-highlight-lang-smalltalk mw-content-ltr" dir="ltr"><pre><span class="nv">var</span> <span class="nf">=</span> <span class="nv">condition</span>
<span class="nb">ifTrue:</span> [ <span class="s">'foo'</span> ]
<span class="nb">ifFalse:</span> [ <span class="s">'bar'</span> ]
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="JavaScript">JavaScript</h3></div>
<p><a href="JavaScript" title="JavaScript">JavaScript</a> uses if-else statements similar to those in <a href="C_syntax" title="C syntax">C</a> languages. A Boolean value is accepted within parentheses between the reserved <i>if</i> keyword and a left curly bracket.
</p>
<div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">()</span><span class="w"> </span><span class="o">&lt;</span><span class="w"> </span><span class="mf">0.5</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"You got Heads!"</span><span class="p">);</span>
<span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"You got Tails!"</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
<p>The above example takes the conditional of <code>Math.random() &lt; 0.5</code> which outputs <code>true</code> if a random float value between 0 and 1 is greater than 0.5. The statement uses it to randomly choose between outputting <code>You got Heads!</code> or <code>You got Tails!</code> to the console. Else and else-if statements can also be chained after the curly bracket of the statement preceding it as many times as necessary, as shown below:
</p>
<div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span class="kd">var</span><span class="w"> </span><span class="nx">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">();</span>
<span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="nx">x</span><span class="w"> </span><span class="o">&lt;</span><span class="w"> </span><span class="mf">1</span><span class="o">/</span><span class="mf">3</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"One person won!"</span><span class="p">);</span>
<span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="nx">x</span><span class="w"> </span><span class="o">&lt;</span><span class="w"> </span><span class="mf">2</span><span class="o">/</span><span class="mf">3</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"Two people won!"</span><span class="p">);</span>
<span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"It's a three-way tie!"</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="Lambda_calculus">Lambda calculus</h3></div>
<p>In <a href="Lambda_calculus" title="Lambda calculus">Lambda calculus</a>, the concept of an if-then-else conditional can be expressed using the following expressions:
</p>
<pre>true = λx. λy. x
false = λx. λy. y
ifThenElse = (λc. λx. λy. (c x y))
</pre>
<ol><li>true takes up to two arguments and once both are provided (see <a href="Currying" title="Currying">currying</a>), it returns the first argument given.</li>
<li>false takes up to two arguments and once both are provided(see <a href="Currying" title="Currying">currying</a>), it returns the second argument given.</li>
<li>ifThenElse takes up to three arguments and once all are provided, it passes both second and third argument to the first argument(which is a function that given two arguments, and produces a result). We expect ifThenElse to only take true or false as an argument, both of which project the given two arguments to their preferred single argument, which is then returned.</li></ol>
<p><b>note</b>: if ifThenElse is passed two functions as the left and right conditionals; it is <b>necessary</b> to also pass an empty tuple () to the result of ifThenElse in order to actually call the chosen function, otherwise ifThenElse will just return the <a href="Function_object" title="Function object">function object</a> without getting called.
</p><p>In a system where numbers can be used without definition (like Lisp, Traditional paper math, so on), the above can be expressed as a single closure below:
</p>
<div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span class="p">((</span><span class="nv">λtrue.</span><span class="w"> </span><span class="nv">λfalse.</span><span class="w"> </span><span class="nv">λifThenElse.</span>
<span class="w"> </span><span class="p">(</span><span class="nv">ifThenElse</span><span class="w"> </span><span class="nv">true</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="mi">3</span><span class="p">)</span>
<span class="p">)(</span><span class="nv">λx.</span><span class="w"> </span><span class="nv">λy.</span><span class="w"> </span><span class="nv">x</span><span class="p">)(</span><span class="nv">λx.</span><span class="w"> </span><span class="nv">λy.</span><span class="w"> </span><span class="nv">y</span><span class="p">)(</span><span class="nv">λc.</span><span class="w"> </span><span class="nv">λl.</span><span class="w"> </span><span class="nv">λr.</span><span class="w"> </span><span class="nv">c</span><span class="w"> </span><span class="nv">l</span><span class="w"> </span><span class="nv">r</span><span class="p">))</span>
</pre></div>
<p>Here, true, false, and ifThenElse are bound to their respective definitions which are passed to their scope at the end of their block.
</p><p>A working JavaScript analogy(using only functions of single variable for rigor) to this is as follows:
</p>
<div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span class="kd">var</span><span class="w"> </span><span class="nx">computationResult</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">((</span><span class="nx">_true</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="nx">_false</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="nx">_ifThenElse</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span>
<span class="w"> </span><span class="nx">_ifThenElse</span><span class="p">(</span><span class="nx">_true</span><span class="p">)(</span><span class="mf">2</span><span class="p">)(</span><span class="mf">3</span><span class="p">)</span><span class="w"> </span>
<span class="p">)(</span><span class="nx">x</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="nx">y</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="nx">x</span><span class="p">)(</span><span class="nx">x</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="nx">y</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="nx">y</span><span class="p">)(</span><span class="nx">c</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="nx">x</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="nx">y</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="nx">c</span><span class="p">(</span><span class="nx">x</span><span class="p">)(</span><span class="nx">y</span><span class="p">)));</span>
</pre></div>
<p>The code above with multivariable functions looks like this:
</p>
<div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span class="kd">var</span><span class="w"> </span><span class="nx">computationResult</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">((</span><span class="nx">_true</span><span class="p">,</span><span class="w"> </span><span class="nx">_false</span><span class="p">,</span><span class="w"> </span><span class="nx">_ifThenElse</span><span class="p">)</span><span class="w"> </span><span class="p">=&gt;</span>
<span class="w"> </span><span class="nx">_ifThenElse</span><span class="p">(</span><span class="nx">_true</span><span class="p">,</span><span class="w"> </span><span class="mf">2</span><span class="p">,</span><span class="w"> </span><span class="mf">3</span><span class="p">)</span>
<span class="p">)((</span><span class="nx">x</span><span class="p">,</span><span class="w"> </span><span class="nx">y</span><span class="p">)</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="nx">x</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="nx">x</span><span class="p">,</span><span class="w"> </span><span class="nx">y</span><span class="p">)</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="nx">y</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="nx">c</span><span class="p">,</span><span class="w"> </span><span class="nx">x</span><span class="p">,</span><span class="w"> </span><span class="nx">y</span><span class="p">)</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="nx">c</span><span class="p">(</span><span class="nx">x</span><span class="p">,</span><span class="w"> </span><span class="nx">y</span><span class="p">));</span>
</pre></div>
<p>Another version of the earlier example without a system where numbers are assumed is below.
</p><p>The first example shows the first branch being taken, while second example shows the second branch being taken.
</p>
<div class="mw-highlight mw-highlight-lang-lisp mw-content-ltr" dir="ltr"><pre><span class="p">((</span><span class="nv">λtrue.</span><span class="w"> </span><span class="nv">λfalse.</span><span class="w"> </span><span class="nv">λifThenElse.</span>
<span class="w"> </span><span class="p">(</span><span class="nv">ifThenElse</span><span class="w"> </span><span class="nv">true</span><span class="w"> </span><span class="p">(</span><span class="nv">λFirstBranch.</span><span class="w"> </span><span class="nv">FirstBranch</span><span class="p">)</span><span class="w"> </span><span class="p">(</span><span class="nv">λSecondBranch.</span><span class="w"> </span><span class="nv">SecondBranch</span><span class="p">))</span>
<span class="p">)(</span><span class="nv">λx.</span><span class="w"> </span><span class="nv">λy.</span><span class="w"> </span><span class="nv">x</span><span class="p">)(</span><span class="nv">λx.</span><span class="w"> </span><span class="nv">λy.</span><span class="w"> </span><span class="nv">y</span><span class="p">)(</span><span class="nv">λc.</span><span class="w"> </span><span class="nv">λl.</span><span class="w"> </span><span class="nv">λr.</span><span class="w"> </span><span class="nv">c</span><span class="w"> </span><span class="nv">l</span><span class="w"> </span><span class="nv">r</span><span class="p">))</span>

<span class="p">((</span><span class="nv">λtrue.</span><span class="w"> </span><span class="nv">λfalse.</span><span class="w"> </span><span class="nv">λifThenElse.</span>
<span class="w"> </span><span class="p">(</span><span class="nv">ifThenElse</span><span class="w"> </span><span class="nv">false</span><span class="w"> </span><span class="p">(</span><span class="nv">λFirstBranch.</span><span class="w"> </span><span class="nv">FirstBranch</span><span class="p">)</span><span class="w"> </span><span class="p">(</span><span class="nv">λSecondBranch.</span><span class="w"> </span><span class="nv">SecondBranch</span><span class="p">))</span>
<span class="p">)(</span><span class="nv">λx.</span><span class="w"> </span><span class="nv">λy.</span><span class="w"> </span><span class="nv">x</span><span class="p">)(</span><span class="nv">λx.</span><span class="w"> </span><span class="nv">λy.</span><span class="w"> </span><span class="nv">y</span><span class="p">)(</span><span class="nv">λc.</span><span class="w"> </span><span class="nv">λl.</span><span class="w"> </span><span class="nv">λr.</span><span class="w"> </span><span class="nv">c</span><span class="w"> </span><span class="nv">l</span><span class="w"> </span><span class="nv">r</span><span class="p">))</span>
</pre></div>
<p>Smalltalk uses a similar idea for its true and false representations, with True and False being singleton objects that respond to messages ifTrue/ifFalse differently.
</p><p>Haskell used to use this exact model for its Boolean type, but at the time of writing, most Haskell programs use syntactic sugar "if a then b else c" construct which unlike ifThenElse does not compose unless
either wrapped in another function or re-implemented as shown in The Haskell section of this page.
</p>
<div class="mw-heading mw-heading2"><h2 id="Case_and_switch_statements">Case and switch statements</h2></div>
<div role="note" class="hatnote navigation-not-searchable">Main article: <a href="Switch_statement" title="Switch statement">Switch statement</a></div>
<p><a href="Switch_statement" title="Switch statement">Switch statements</a> (in some languages, <i>case statements</i> or multiway branches) compare a given value with specified constants and take action according to the first constant to match. There is usually a provision for a default action ('else','otherwise') to be taken if no match succeeds. Switch statements can allow <a href="Optimizing_compiler" title="Optimizing compiler">compiler optimizations</a>, such as <a href="Lookup_table" title="Lookup table">lookup tables</a>. In dynamic languages, the cases may not be limited to constant expressions, and might extend to <a href="Pattern_matching" title="Pattern matching">pattern matching</a>, as in the <a href="Shell_script" title="Shell script">shell script</a> example on the right, where the '*)' implements the default case as a <a href="Regular_expression" title="Regular expression">regular expression</a> matching any string.
</p>
<table class="wikitable">

<tbody><tr>
<th><a href="Pascal_(programming_language)" title="Pascal (programming language)">Pascal</a>:
</th>
<th><a href="C_(programming_language)" title="C (programming language)">C</a>:
</th>
<th><a href="Shell_script" title="Shell script">Shell script</a>:
</th></tr>
<tr>
<td><div class="mw-highlight mw-highlight-lang-pascal mw-content-ltr" dir="ltr"><pre><span class="k">case</span><span class="w"> </span><span class="n">someChar</span><span class="w"> </span><span class="k">of</span>
<span class="w"> </span><span class="s">'a'</span><span class="o">:</span><span class="w"> </span><span class="n">actionOnA</span><span class="o">;</span>
<span class="w"> </span><span class="s">'x'</span><span class="o">:</span><span class="w"> </span><span class="n">actionOnX</span><span class="o">;</span>
<span class="w"> </span><span class="s">'y'</span><span class="o">,</span><span class="s">'z'</span><span class="o">:</span><span class="n">actionOnYandZ</span><span class="o">;</span>
<span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="n">actionOnNoMatch</span><span class="o">;</span>
<span class="k">end</span><span class="o">;</span>
</pre></div>
</td>
<td><div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span class="k">switch</span><span class="w"> </span><span class="p">(</span><span class="n">someChar</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">case</span><span class="w"> </span><span class="sc">'a'</span><span class="p">:</span><span class="w"> </span><span class="n">actionOnA</span><span class="p">;</span><span class="w"> </span><span class="k">break</span><span class="p">;</span>
<span class="w"> </span><span class="k">case</span><span class="w"> </span><span class="sc">'x'</span><span class="p">:</span><span class="w"> </span><span class="n">actionOnX</span><span class="p">;</span><span class="w"> </span><span class="k">break</span><span class="p">;</span>
<span class="w"> </span><span class="k">case</span><span class="w"> </span><span class="sc">'y'</span><span class="p">:</span>
<span class="w"> </span><span class="k">case</span><span class="w"> </span><span class="sc">'z'</span><span class="p">:</span><span class="w"> </span><span class="n">actionOnYandZ</span><span class="p">;</span><span class="w"> </span><span class="k">break</span><span class="p">;</span>
<span class="w"> </span><span class="k">default</span><span class="o">:</span><span class="w"> </span><span class="n">actionOnNoMatch</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
</td>
<td><div class="mw-highlight mw-highlight-lang-bash mw-content-ltr" dir="ltr"><pre><span class="k">case</span><span class="w"> </span><span class="nv">$someChar</span><span class="w"> </span><span class="k">in</span><span class="w"> </span>
<span class="w"> </span>a<span class="o">)</span><span class="w"> </span>actionOnA<span class="p">;</span><span class="w"> </span><span class="p">;;</span>
<span class="w"> </span>x<span class="o">)</span><span class="w"> </span>actionOnX<span class="p">;</span><span class="w"> </span><span class="p">;;</span>
<span class="w"> </span><span class="o">[</span>yz<span class="o">])</span><span class="w"> </span>actionOnYandZ<span class="p">;</span><span class="w"> </span><span class="p">;;</span>
<span class="w"> </span>*<span class="o">)</span><span class="w"> </span>actionOnNoMatch<span class="w"> </span><span class="p">;;</span>
<span class="k">esac</span>
</pre></div>
</td></tr></tbody></table>
<div class="mw-heading mw-heading2"><h2 id="Pattern_matching">Pattern matching</h2></div>
<div role="note" class="hatnote navigation-not-searchable">Main article: <a href="Pattern_matching" title="Pattern matching">Pattern matching</a></div>
<p><a href="Pattern_matching" title="Pattern matching">Pattern matching</a> may be seen as an alternative to both <i>if–then–else</i>, and <i>case</i> statements. It is available in many programming languages with functional programming features, such as <a href="Wolfram_Language" title="Wolfram Language">Wolfram Language</a>, <a href="ML_(programming_language)" title="ML (programming language)">ML</a> and many others. Here is a simple example written in the <a href="OCaml" title="OCaml">OCaml</a> language:
</p>
<div class="mw-highlight mw-highlight-lang-ocaml mw-content-ltr" dir="ltr"><pre><span class="k">match</span> <span class="n">fruit</span> <span class="k">with</span>
<span class="o">|</span> <span class="s2">"apple"</span> <span class="o">-&gt;</span> <span class="n">cook</span> <span class="n">pie</span>
<span class="o">|</span> <span class="s2">"coconut"</span> <span class="o">-&gt;</span> <span class="n">cook</span> <span class="n">dango_mochi</span>
<span class="o">|</span> <span class="s2">"banana"</span> <span class="o">-&gt;</span> <span class="n">mix</span><span class="o">;;</span>
</pre></div>
<p>The power of pattern matching is the ability to <i>concisely</i> match not only actions but also <i>values</i> to patterns of data. Here is an example written in <a href="Haskell_(programming_language)" class="mw-redirect" title="Haskell (programming language)">Haskell</a> which illustrates both of these features:
</p>
<div class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><pre><span class="nf">map</span><span class="w"> </span><span class="kr">_</span><span class="w"> </span><span class="kt">[]</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="kt">[]</span>
<span class="nf">map</span><span class="w"> </span><span class="n">f</span><span class="w"> </span><span class="p">(</span><span class="n">h</span><span class="w"> </span><span class="kt">:</span><span class="w"> </span><span class="n">t</span><span class="p">)</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">f</span><span class="w"> </span><span class="n">h</span><span class="w"> </span><span class="kt">:</span><span class="w"> </span><span class="n">map</span><span class="w"> </span><span class="n">f</span><span class="w"> </span><span class="n">t</span>
</pre></div>
<p>This code defines a function <i>map</i>, which applies the first argument (a function) to each of the elements of the second argument (a list), and returns the resulting list. The two lines are the two definitions of the function for the two kinds of arguments possible in this case – one where the list is empty (just return an empty list) and the other case where the list is not empty.
</p><p>Pattern matching is not strictly speaking <i>always</i> a choice construct, because it is possible in Haskell to write only one alternative, which is guaranteed to always be matched – in this situation, it is not being used as a choice construct, but simply as a way to bind names to values. However, it is frequently used as a choice construct in the languages in which it is available.
</p>
<div class="mw-heading mw-heading2"><h2 id="Hash-based_conditionals">Hash-based conditionals</h2></div>
<p>In programming languages that have <a href="Associative_array" title="Associative array">associative arrays</a> or comparable data structures, such as <a href="Python_(programming_language)" title="Python (programming language)">Python</a>, <a href="Perl" title="Perl">Perl</a>, <a href="PHP" title="PHP">PHP</a> or <a href="Objective-C" title="Objective-C">Objective-C</a>, it is idiomatic to use them to implement conditional assignment.<sup id="cite_ref-13" class="reference"><a href="#cite_note-13"><span class="cite-bracket">[</span>13<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span class="n">pet</span> <span class="o">=</span> <span class="nb">input</span><span class="p">(</span><span class="s2">"Enter the type of pet you want to name: "</span><span class="p">)</span>
<span class="n">known_pets</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">"Dog"</span><span class="p">:</span> <span class="s2">"Fido"</span><span class="p">,</span>
<span class="s2">"Cat"</span><span class="p">:</span> <span class="s2">"Meowsles"</span><span class="p">,</span>
<span class="s2">"Bird"</span><span class="p">:</span> <span class="s2">"Tweety"</span><span class="p">,</span>
<span class="p">}</span>
<span class="n">my_name</span> <span class="o">=</span> <span class="n">known_pets</span><span class="p">[</span><span class="n">pet</span><span class="p">]</span>
</pre></div>
<p>In languages that have <a href="Anonymous_function" title="Anonymous function">anonymous functions</a> or that allow a programmer to assign a named function to a variable reference, conditional flow can be implemented by using a hash as a <a href="Dispatch_table" title="Dispatch table">dispatch table</a>.
</p>
<div class="mw-heading mw-heading2"><h2 id="Predication">Predication</h2></div>
<div role="note" class="hatnote navigation-not-searchable">Main article: <a href="Branch_predication" class="mw-redirect" title="Branch predication">Branch predication</a></div>
<p>An alternative to conditional branch instructions is <a href="Branch_predication" class="mw-redirect" title="Branch predication">predication</a>. Predication is an <a href="Instruction_set_architecture" title="Instruction set architecture">architectural</a> feature that enables instructions to be conditionally executed instead of modifying the <a href="Control_flow" title="Control flow">control flow</a>.
</p>
<div class="mw-heading mw-heading2"><h2 id="Choice_system_cross_reference">Choice system cross reference</h2></div>
<p>This table refers to the most recent language specification of each language. For languages that do not have a specification, the latest officially released implementation is referred to.
</p>
<table class="wikitable">

<tbody><tr>
<th rowspan="2"><a href="Programming_language" title="Programming language">Programming language</a>
</th>
<th colspan="3">Structured if
</th>
<th rowspan="2"><a href="Switch_statement" title="Switch statement">switch</a>–select–case
</th>
<th rowspan="2">Conditional expressions
</th>
<th rowspan="2"><a href="Arithmetic_IF" class="mw-redirect" title="Arithmetic IF">Arithmetic if</a>
</th>
<th rowspan="2"><a href="Pattern_matching" title="Pattern matching">Pattern matching</a><style data-mw-deduplicate="TemplateStyles:r1041539562">
/* start https://en.wikipedia.org/ */


.mw-parser-output .citation{word-wrap:break-word}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}


/* end https://en.wikipedia.org/ */
</style><sup class="citation nobold" id="ref_pattern_matchingnone"><a href="#endnote_pattern_matchingnone">[A]</a></sup>
</th></tr>
<tr>
<th>then
</th>
<th>else
</th>
<th>else–if
</th></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="Ada_(programming_language)" title="Ada (programming language)">Ada</a>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="ALGOL-60" class="mw-redirect" title="ALGOL-60">ALGOL-60</a>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background: #FFE3E3; color: black; vertical-align: middle; text-align: center;" class="table-no2">Unneeded<sup class="citation nobold" id="ref_choice_else_if2"><a href="#endnote_choice_else_if2">[C]</a></sup>
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="APL_(programming_language)" title="APL (programming language)">APL</a>
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="Bash_(Unix_shell)" title="Bash (Unix shell)">Bash shell</a>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="C_(programming_language)" title="C (programming language)">C</a>, <a href="C%2B%2B" title="C++">C++</a>
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background: #FFE3E3; color: black; vertical-align: middle; text-align: center;" class="table-no2">Unneeded<sup class="citation nobold" id="ref_preprocessor_elif1"><a href="#endnote_preprocessor_elif1">[B]</a></sup><sup class="citation nobold" id="ref_choice_else_if6"><a href="#endnote_choice_else_if6">[C]</a></sup>
</td>
<td style="background:#bfd; color:black; vertical-align:middle; text-align:center;" class="table-yes2">Fall-through
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="C_Sharp_(programming_language)" title="C Sharp (programming language)">C#</a>
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background: #FFE3E3; color: black; vertical-align: middle; text-align: center;" class="table-no2">Unneeded<sup class="citation nobold" id="ref_preprocessor_elif2"><a href="#endnote_preprocessor_elif2">[B]</a></sup><sup class="citation nobold" id="ref_choice_else_if2"><a href="#endnote_choice_else_if2">[C]</a></sup>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="COBOL" title="COBOL">COBOL</a>
</td>
<td style="background: #FFE3E3; color: black; vertical-align: middle; text-align: center;" class="table-no2">Unneeded
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background: #FFE3E3; color: black; vertical-align: middle; text-align: center;" class="table-no2">Unneeded<sup class="citation nobold" id="ref_choice_else_if2"><a href="#endnote_choice_else_if2">[C]</a></sup>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="Eiffel_(programming_language)" title="Eiffel (programming language)">Eiffel</a>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes"><a href="Switch_statement#Eiffel" title="Switch statement">Yes</a>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="F_Sharp_(programming_language)" title="F Sharp (programming language)">F#</a>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes<sup class="citation nobold" id="ref_choice_const1"><a href="#endnote_choice_const1">[D]</a></sup>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="Fortran" title="Fortran">Fortran</a>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes<sup class="citation nobold" id="ref_fortrannone"><a href="#endnote_fortrannone">[G]</a></sup>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes<sup class="citation nobold" id="ref_fortrannone"><a href="#endnote_fortrannone">[I]</a></sup>
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="Go_(programming_language)" title="Go (programming language)">Go</a>
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background: #FFE3E3; color: black; vertical-align: middle; text-align: center;" class="table-no2">Unneeded<sup class="citation nobold" id="ref_choice_else_if1"><a href="#endnote_choice_else_if1">[C]</a></sup>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="Haskell_(programming_language)" class="mw-redirect" title="Haskell (programming language)">Haskell</a>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#bfd; color:black; vertical-align:middle; text-align:center;" class="table-yes2">Needed
</td>
<td style="background: #FFE3E3; color: black; vertical-align: middle; text-align: center;" class="table-no2">Unneeded<sup class="citation nobold" id="ref_choice_else_if3"><a href="#endnote_choice_else_if3">[C]</a></sup>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes<sup class="citation nobold" id="ref_choice_const2"><a href="#endnote_choice_const2">[D]</a></sup>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="Java_(programming_language)" title="Java (programming language)">Java</a>
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background: #FFE3E3; color: black; vertical-align: middle; text-align: center;" class="table-no2">Unneeded<sup class="citation nobold" id="ref_choice_else_if4"><a href="#endnote_choice_else_if4">[C]</a></sup>
</td>
<td style="background:#bfd; color:black; vertical-align:middle; text-align:center;" class="table-yes2">Fall-through<sup id="cite_ref-JLS_14-0" class="reference"><a href="#cite_note-JLS-14"><span class="cite-bracket">[</span>14<span class="cite-bracket">]</span></a></sup>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="ECMAScript" title="ECMAScript">ECMAScript</a> (<a href="JavaScript" title="JavaScript">JavaScript</a>)
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background: #FFE3E3; color: black; vertical-align: middle; text-align: center;" class="table-no2">Unneeded<sup class="citation nobold" id="ref_choice_else_if5"><a href="#endnote_choice_else_if5">[C]</a></sup>
</td>
<td style="background:#bfd; color:black; vertical-align:middle; text-align:center;" class="table-yes2">Fall-through<sup id="cite_ref-ECMA-262_15-0" class="reference"><a href="#cite_note-ECMA-262-15"><span class="cite-bracket">[</span>15<span class="cite-bracket">]</span></a></sup>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="Mathematica" class="mw-redirect" title="Mathematica">Mathematica</a>
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="Oberon_(programming_language)" title="Oberon (programming language)">Oberon</a>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="Perl" title="Perl">Perl</a>
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="PHP" title="PHP">PHP</a>
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#bfd; color:black; vertical-align:middle; text-align:center;" class="table-yes2">Fall-through
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="Pascal_(programming_language)" title="Pascal (programming language)">Pascal</a>, <a href="Object_Pascal" title="Object Pascal">Object Pascal</a> (<a href="Delphi_(programming_language)" class="mw-redirect" title="Delphi (programming language)">Delphi</a>)
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background: #FFE3E3; color: black; vertical-align: middle; text-align: center;" class="table-no2">Unneeded
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="Python_(programming_language)" title="Python (programming language)">Python</a>
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="QuickBASIC" title="QuickBASIC">QuickBASIC</a>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="Ruby_(programming_language)" title="Ruby (programming language)">Ruby</a>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes<sup class="citation nobold" id="ref_rubynone"><a href="#endnote_rubynone">[H]</a></sup>
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="Rust_(programming_language)" title="Rust (programming language)">Rust</a>
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes<sup class="citation nobold" id="ref_choice_const3"><a href="#endnote_choice_const3">[D]</a></sup>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="Scala_(programming_language)" title="Scala (programming language)">Scala</a>
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background: #FFE3E3; color: black; vertical-align: middle; text-align: center;" class="table-no2">Unneeded<sup class="citation nobold" id="ref_choice_else_if4"><a href="#endnote_choice_else_if4">[C]</a></sup>
</td>
<td style="background:#bfd; color:black; vertical-align:middle; text-align:center;" class="table-yes2">Fall-through
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="SQL" title="SQL">SQL</a>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes<sup class="citation nobold" id="ref_SQL1"><a href="#endnote_SQL1">[F]</a></sup>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes<sup class="citation nobold" id="ref_SQL2"><a href="#endnote_SQL2">[F]</a></sup>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="Swift_(programming_language)" title="Swift (programming language)">Swift</a>
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="Tcl" title="Tcl">Tcl</a>
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="Visual_Basic" title="Visual Basic">Visual Basic</a>, classic
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="Visual_Basic_.NET" class="mw-redirect" title="Visual Basic .NET">Visual Basic .NET</a>
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td></tr>
<tr>
<td style="background: #ececec; color: black; font-weight: bold; vertical-align: middle; text-align: left;" class="table-rh"><a href="Windows_PowerShell" class="mw-redirect" title="Windows PowerShell">Windows PowerShell</a>
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#bfd; color:black; vertical-align:middle; text-align:center;" class="table-yes2">Fall-through
</td>
<td style="background:#9EFF9E;color:black;vertical-align:middle;text-align:center;" class="table-yes">Yes
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td>
<td style="background:#FFC7C7;color:black;vertical-align:middle;text-align:center;" class="table-no">No
</td></tr></tbody></table>
<div><ol style="list-style-type:upper-alpha"><li><span class="citation wikicite" id="endnote_pattern_matchingnone"><a href="#ref_pattern_matchingnone"><b><sup>^</sup></b></a></span> This refers to pattern matching as a distinct conditional construct in the programming language – as opposed to mere string pattern matching support, such as <a href="Regular_expression" title="Regular expression">regular expression</a> support.</li><li><span class="citation wikicite" id="endnote_preprocessor_elif1"><a href="#ref_preprocessor_elif1"><b><sup>1</sup></b></a></span> <span class="citation wikicite" id="endnote_preprocessor_elif2"><a href="#ref_preprocessor_elif2"><b><sup>2</sup></b></a></span> An #ELIF directive is used in the <a href="Preprocessor" title="Preprocessor">preprocessor</a> sub-language that is used to modify the code before compilation; and to <a href="Include_directive" title="Include directive">include</a> other files.</li><li><span class="citation wikicite" id="endnote_choice_else_if1"><a href="#ref_choice_else_if1"><b><sup>1</sup></b></a></span> <span class="citation wikicite" id="endnote_choice_else_if2"><a href="#ref_choice_else_if2"><b><sup>2</sup></b></a></span> <span class="citation wikicite" id="endnote_choice_else_if3"><a href="#ref_choice_else_if3"><b><sup>3</sup></b></a></span> <span class="citation wikicite" id="endnote_choice_else_if4"><a href="#ref_choice_else_if4"><b><sup>4</sup></b></a></span> <span class="citation wikicite" id="endnote_choice_else_if5"><a href="#ref_choice_else_if5"><b><sup>5</sup></b></a></span> <span class="citation wikicite" id="endnote_choice_else_if6"><a href="#ref_choice_else_if6"><b><sup>6</sup></b></a></span> The often-encountered <code>else if</code> in the C family of languages, and in COBOL and Haskell, is not a language feature but a set of nested and independent <i>if then else</i> statements combined with a particular source code layout. However, this also means that a distinct else–if construct is not really needed in these languages.</li><li><span class="citation wikicite" id="endnote_choice_const1"><a href="#ref_choice_const1"><b><sup>1</sup></b></a></span> <span class="citation wikicite" id="endnote_choice_const2"><a href="#ref_choice_const2"><b><sup>2</sup></b></a></span> <span class="citation wikicite" id="endnote_choice_const3"><a href="#ref_choice_const3"><b><sup>3</sup></b></a></span> Case-expressions in Haskell and match-expressions in F# and Haskell allow both switch-case and pattern matching usage.</li><li><span class="citation wikicite" id="endnote_case_regexpnone"><a href="#ref_case_regexpnone"><b><sup>^</sup></b></a></span> In a Ruby <code>case</code> construct, <a href="Regular_expression" title="Regular expression">regular expression</a> matching is among the conditional flow-control alternatives available. For an example, see <a rel="nofollow" class="external text" href="https://stackoverflow.com/q/6803647">this</a> Stack Overflow question.</li><li><span class="citation wikicite" id="endnote_SQL1"><a href="#ref_SQL1"><b><sup>1</sup></b></a></span> <span class="citation wikicite" id="endnote_SQL2"><a href="#ref_SQL2"><b><sup>2</sup></b></a></span> SQL has two similar constructs that fulfill both roles, both introduced in <a href="SQL-92" title="SQL-92">SQL-92</a>. A "searched <code>CASE</code>" expression <code class="mw-highlight mw-highlight-lang-sql mw-content-ltr" style="" dir="ltr"><span class="k">CASE</span><span class="w"> </span><span class="k">WHEN</span><span class="w"> </span><span class="n">cond1</span><span class="w"> </span><span class="k">THEN</span><span class="w"> </span><span class="n">expr1</span><span class="w"> </span><span class="k">WHEN</span><span class="w"> </span><span class="n">cond2</span><span class="w"> </span><span class="k">THEN</span><span class="w"> </span><span class="n">expr2</span><span class="w"> </span><span class="p">[...]</span><span class="w"> </span><span class="k">ELSE</span><span class="w"> </span><span class="n">exprDflt</span><span class="w"> </span><span class="k">END</span></code> works like <code>if ... else if ... else</code>, whereas a "simple <code>CASE</code>" expression: <code class="mw-highlight mw-highlight-lang-sql mw-content-ltr" style="" dir="ltr"><span class="k">CASE</span><span class="w"> </span><span class="n">expr</span><span class="w"> </span><span class="k">WHEN</span><span class="w"> </span><span class="n">val1</span><span class="w"> </span><span class="k">THEN</span><span class="w"> </span><span class="n">expr1</span><span class="w"> </span><span class="p">[...]</span><span class="w"> </span><span class="k">ELSE</span><span class="w"> </span><span class="n">exprDflt</span><span class="w"> </span><span class="k">END</span></code> works like a switch statement. For details and examples see <a href="Case_(SQL)" class="mw-redirect" title="Case (SQL)">Case (SQL)</a>.</li><li><span class="citation wikicite" id="endnote_fortrannone"><a href="#ref_fortrannone"><b><sup>^</sup></b></a></span> Fortran 90 added the <code>MERGE</code> intrinsic. Fortran 2023 added the C-like ternary operator.</li><li><span class="citation wikicite" id="endnote_rubynone"><a href="#ref_rubynone"><b><sup>^</sup></b></a></span> Pattern matching was added in Ruby 3.0.<sup id="cite_ref-16" class="reference"><a href="#cite_note-16"><span class="cite-bracket">[</span>16<span class="cite-bracket">]</span></a></sup> Some pattern matching constructs are still experimental.</li><li><span class="citation wikicite" id="endnote_fortrannone"><a href="#ref_fortrannone"><b><sup>^</sup></b></a></span> Arithmetic <code>if</code> was marked as obsolescent in Fortran 90. It was deleted as of the Fortran 2018 Standard.</li></ol></div>
<div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1266661725">
/* start https://en.wikipedia.org/ */


.mw-parser-output .portalbox{padding:0;margin:0.5em 0;display:table;box-sizing:border-box;max-width:175px;list-style:none}.mw-parser-output .portalborder{border:1px solid var(--border-color-base,#a2a9b1);padding:0.1em;background:var(--background-color-neutral-subtle,#f8f9fa)}.mw-parser-output .portalbox-entry{display:table-row;font-size:85%;line-height:110%;height:1.9em;font-style:italic;font-weight:bold}.mw-parser-output .portalbox-image{display:table-cell;padding:0.2em;vertical-align:middle;text-align:center}.mw-parser-output .portalbox-link{display:table-cell;padding:0.2em 0.2em 0.2em 0.3em;vertical-align:middle}@media(min-width:720px){.mw-parser-output .portalleft{margin:0.5em 1em 0.5em 0}.mw-parser-output .portalright{clear:right;float:right;margin:0.5em 0 0.5em 1em}}


/* end https://en.wikipedia.org/ */
</style>
<ul><li><a href="Branch_(computer_science)" title="Branch (computer science)">Branch (computer science)</a></li>
<li><a href="Conditional_compilation" title="Conditional compilation">Conditional compilation</a></li>
<li><a href="Dynamic_dispatch" title="Dynamic dispatch">Dynamic dispatch</a> for another way to make execution choices</li>
<li><a href="McCarthy_Formalism" title="McCarthy Formalism">McCarthy Formalism</a> for history and historical references</li>
<li><a href="Named_condition" class="mw-redirect" title="Named condition">Named condition</a></li>
<li><a href="Relational_operator" title="Relational operator">Relational operator</a></li>
<li><a href="Test_(Unix)" title="Test (Unix)">Test (Unix)</a></li>
<li><a href="Yoda_conditions" title="Yoda conditions">Yoda conditions</a></li>
<li><a href="Conditional_move" class="mw-redirect" title="Conditional move">Conditional move</a></li></ul>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */


.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}


/* end https://en.wikipedia.org/ */
</style><div class="reflist">
<div class="mw-references-wrap mw-references-columns"><ol class="references">
<li id="cite_note-php_elseif-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-php_elseif_1-0">^</a></b></span> <span class="reference-text"><i><a rel="nofollow" class="external text" href="http://php.net/manual/control-structures.elseif.php">PHP elseif syntax</a></i></span>
</li>
<li id="cite_note-vb_elseif-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-vb_elseif_2-0">^</a></b></span> <span class="reference-text"><i><a rel="nofollow" class="external text" href="https://docs.microsoft.com/dotnet/visual-basic/language-reference/statements/if-then-else-statement">Visual Basic ElseIf syntax</a></i></span>
</li>
<li id="cite_note-posixshell-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-posixshell_3-0">^</a></b></span> <span class="reference-text"><i><a rel="nofollow" class="external text" href="http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html">POSIX standard shell syntax</a></i></span>
</li>
<li id="cite_note-haskell98report-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-haskell98report_4-0">^</a></b></span> <span class="reference-text"><i><a rel="nofollow" class="external text" href="http://www.haskell.org/onlinereport/">Haskell 98 Language and Libraries: The Revised Report</a></i></span>
</li>
<li id="cite_note-haskell-ifthenelse-proposal-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-haskell-ifthenelse-proposal_5-0">^</a></b></span> <span class="reference-text">"<a rel="nofollow" class="external text" href="http://haskell.org/haskellwiki/If-then-else">If-then-else Proposal on HaskellWiki</a>"</span>
</li>
<li id="cite_note-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-6">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */


.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}


/* end https://en.wikipedia.org/ */
</style><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://embeddedgurus.com/stack-overflow/2009/02/efficient-c-tips-6-dont-use-the-ternary-operator/">"Efficient C Tips #6 – Don't use the ternary operator «&nbsp;Stack Overflow"</a>. Embeddedgurus.com. 2009-02-18<span class="reference-accessdate">. Retrieved <span class="nowrap">2012-09-07</span></span>.</cite></span>
</li>
<li id="cite_note-7"><span class="mw-cite-backlink"><b><a href="#cite_ref-7">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://wiki.tcl-lang.org/page/New+Control+Structures">"New Control Structures"</a>. Tcler's wiki<span class="reference-accessdate">. Retrieved <span class="nowrap">August 21,</span> 2020</span>.</cite></span>
</li>
<li id="cite_note-8"><span class="mw-cite-backlink"><b><a href="#cite_ref-8">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://www.tcl.tk/man/tcl8.6/TclCmd/uplevel.htm">"uplevel manual page"</a>. www.tcl.tk<span class="reference-accessdate">. Retrieved <span class="nowrap">August 21,</span> 2020</span>.</cite></span>
</li>
<li id="cite_note-9"><span class="mw-cite-backlink"><b><a href="#cite_ref-9">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://www.tcl.tk/man/tcl8.6/TclCmd/if.htm">"if manual page"</a>. www.tcl.tk<span class="reference-accessdate">. Retrieved <span class="nowrap">August 21,</span> 2020</span>.</cite></span>
</li>
<li id="cite_note-10"><span class="mw-cite-backlink"><b><a href="#cite_ref-10">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://doc.rust-lang.org/reference/expressions/if-expr.html">"If and if let expressions"</a><span class="reference-accessdate">. Retrieved <span class="nowrap">November 1,</span> 2020</span>.</cite></span>
</li>
<li id="cite_note-fortran77-11"><span class="mw-cite-backlink"><b><a href="#cite_ref-fortran77_11-0">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20071011055359/http://www.fortran.com/fortran/F77_std/rjcnf0001-sh-11.html#sh-11.4">"American National Standard Programming Language FORTRAN"</a>. 1978-04-03. Archived from <a rel="nofollow" class="external text" href="http://www.fortran.com/fortran/F77_std/rjcnf0001-sh-11.html#sh-11.4">the original</a> on 2007-10-11<span class="reference-accessdate">. Retrieved <span class="nowrap">2007-09-09</span></span>.</cite></span>
</li>
<li id="cite_note-Smalltalk_conditionals-12"><span class="mw-cite-backlink"><b><a href="#cite_ref-Smalltalk_conditionals_12-0">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20071022201949/http://wiki.cs.uiuc.edu/VisualWorks/Conditional+Processing">"VisualWorks: Conditional Processing"</a>. 2006-12-16. Archived from <a rel="nofollow" class="external text" href="http://wiki.cs.uiuc.edu/VisualWorks/Conditional+Processing">the original</a> on 2007-10-22<span class="reference-accessdate">. Retrieved <span class="nowrap">2007-09-09</span></span>.</cite></span>
</li>
<li id="cite_note-13"><span class="mw-cite-backlink"><b><a href="#cite_ref-13">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20150120120833/http://codingstyleguide.com/style/180/python-pythonic-way-to-implement-switchcase-statements">"Pythonic way to implement switch/case statements"</a>. Archived from <a rel="nofollow" class="external text" href="http://codingstyleguide.com/style/180/python-pythonic-way-to-implement-switchcase-statements">the original</a> on 2015-01-20<span class="reference-accessdate">. Retrieved <span class="nowrap">2015-01-19</span></span>.</cite></span>
</li>
<li id="cite_note-JLS-14"><span class="mw-cite-backlink"><b><a href="#cite_ref-JLS_14-0">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="http://java.sun.com/docs/books/jls/download/langspec-3.0.pdf">Java.sun.com</a>, Java Language Specification, 3rd Edition.</span>
</li>
<li id="cite_note-ECMA-262-15"><span class="mw-cite-backlink"><b><a href="#cite_ref-ECMA-262_15-0">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf">Ecma-international.org</a> <a rel="nofollow" class="external text" href="https://web.archive.org/web/20150412040502/http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf">Archived</a> 2015-04-12 at the <a href="Wayback_Machine" title="Wayback Machine">Wayback Machine</a> ECMAScript Language Specification, 5th Edition.</span>
</li>
<li id="cite_note-16"><span class="mw-cite-backlink"><b><a href="#cite_ref-16">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://docs.ruby-lang.org/en/3.0.0/doc/syntax/pattern_matching_rdoc.html">"Pattern Matching"</a>. <i>Documentation for Ruby 3.0</i>.</cite></span>
</li>
</ol></div></div>
<div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1290876196">
/* start https://en.wikipedia.org/ */


.mw-parser-output .side-box{margin:4px 0;box-sizing:border-box;border:1px solid #aaa;font-size:88%;line-height:1.25em;background-color:var(--background-color-interactive-subtle,#f8f9fa);display:flow-root}.mw-parser-output .infobox .side-box{font-size:100%}.mw-parser-output .side-box-abovebelow,.mw-parser-output .side-box-text{padding:0.25em 0.9em}.mw-parser-output .side-box-image{padding:2px 0 2px 0.9em;text-align:center}.mw-parser-output .side-box-imageright{padding:2px 0.9em 2px 0;text-align:center}@media(min-width:500px){.mw-parser-output .side-box-flex{display:flex;align-items:center}.mw-parser-output .side-box-text{flex:1;min-width:0}}@media(min-width:720px){.mw-parser-output .side-box{width:238px}.mw-parser-output .side-box-right{clear:right;float:right;margin-left:1em}.mw-parser-output .side-box-left{margin-right:1em}}


/* end https://en.wikipedia.org/ */
</style><style data-mw-deduplicate="TemplateStyles:r1237033735">
/* start https://en.wikipedia.org/ */


@media print{body.ns-0 .mw-parser-output .sistersitebox{display:none!important}}@media screen{html.skin-theme-clientpref-night .mw-parser-output .sistersitebox img[src*="Wiktionary-logo-en-v2.svg"]{background-color:white}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .sistersitebox img[src*="Wiktionary-logo-en-v2.svg"]{background-color:white}}


/* end https://en.wikipedia.org/ */
</style><div class="side-box side-box-right sistersitebox"><style data-mw-deduplicate="TemplateStyles:r1126788409">
/* start https://en.wikipedia.org/ */


.mw-parser-output .plainlist ol,.mw-parser-output .plainlist ul{line-height:inherit;list-style:none;margin:0;padding:0}.mw-parser-output .plainlist ol li,.mw-parser-output .plainlist ul li{margin-bottom:0}


/* end https://en.wikipedia.org/ */
</style>
<div class="side-box-flex">
<div class="side-box-image"><span class="noviewer" typeof="mw:File"></span></div>
<div class="side-box-text plainlist">Look up <i><b><a href="https://en.wiktionary.org/wiki/then" class="extiw external" title="wiktionary:then">then</a></b></i>&nbsp;or <i><b><a href="https://en.wiktionary.org/wiki/else" class="extiw external" title="wiktionary:else">else</a></b></i> in Wiktionary, the free dictionary.</div></div>
</div>
<ul><li><span class="noviewer" typeof="mw:File"></span> Media related to <a href="https://commons.wikimedia.org/wiki/Category:Conditional_(computer_programming)" class="extiw external" title="commons:Category:Conditional (computer programming)">Conditional (computer programming)</a> at Wikimedia Commons</li>
<li><a rel="nofollow" class="external text" href="http://everythingfla.com/courses/video/8/69/">IF NOT (ActionScript 3.0)</a> video</li></ul></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-08-08" href="https://en.wikipedia.org/wiki/?title=Conditional_(computer_programming)&amp;oldid=1304759993">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>

</body></html>